package homework;

/**
* Created by kevin on 15-1-4.
*/
public class Register<E> {
    final public Item<E> start = new Item();
    int count = 0;
    public Item<E> current = null;
    private class Item<E>{
        private E value;
        private Item next;
        private int count;
    }

    private Item last(){
        Item i=start;
        for(;i.next!=null;i=i.next){
        }
        return i;
    }

    public void add(E value){
        Item p = new Item();
        p.value = value;
        p.next = null;
        Item last = last();
        last.next = p;
    }

    public void startIteration(){
        for(Item i=start;i.next!=null;i=i.next){
        }
        current = start;
    }
    public E next(){
        if(current == start){
            current = current.next;
        }
        current = current.next;
        return  current.value;
    }
    public boolean hasNext(){
        if(current.next != null){
            return true;
        }else{
            return false;
        }
    }
    public void deleteCurrent(){
        current.value = null;

    }
}
